package com.xiaotu.dao.sw;

import com.xiaotu.model.SwConcernModel;
import com.xiaotu.vo.SwConcernsVo;
import com.xiaotu.vo.SwFansVo;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author zhangxiao
 * @create 2021-09-02 13:50
 */
public interface SwConcernMapper extends Mapper<SwConcernModel> {

    @Select("<script>" +
            " SELECT " +
            " t3.starid, " +
            " t2.nick_name, " +
            " t2.avatar_url, " +
            " CASE t2.auth_status WHEN 2 THEN 1 ELSE 0 END AS auth_status " +
            "FROM " +
            " tab_sw_concern t1 " +
            " LEFT JOIN tab_wx_user t2 ON t1.concern_user_id = t2.userid " +
            " LEFT JOIN tab_sw_user t3 ON t3.userid = t1.concern_user_id  " +
            "WHERE " +
            " t1.be_concern_star_id = #{starId}  " +
            " AND t1.concern_status = 1  " +
            "ORDER BY " +
            " t1.update_time DESC " +
            "</script>")
    List<SwFansVo> getMyFans(Integer starId);

    @Select("<script>" +
            " SELECT " +
            " t1.be_concern_star_id starId, " +
            " MAX( t2.imagesurl ) imagesUrl, " +
            " MAX( t2.NAME ) starName, " +
            " MAX( t2.occupation ) occupation, " +
            " MAX( t2.representativework ) works, " +
            " MAX( t1.update_time ) concernTime, " +
            " COUNT( t5.tvid ) workTotal, " +
            " COUNT( t4.userid ) isAuthSuccess  " +
            "FROM " +
            " tab_sw_concern t1 " +
            " LEFT JOIN tab_star_info t2 ON t1.be_concern_star_id = t2.starid " +
            " LEFT JOIN tab_sw_user t3 ON t3.starid = t1.be_concern_star_id " +
            " LEFT JOIN tab_wx_user t4 ON t4.userid = t3.userid  " +
            " AND t4.auth_status = 2 " +
            " LEFT JOIN tab_screenwriter_works t5 ON t1.be_concern_star_id = t5.starid " +
            " INNER JOIN tab_tv_info t6 ON t5.tvid = t6.tvid  " +
            " AND t6.tvtype IN ( 1, 2, 3, 6 )  " +
            "WHERE " +
            " t1.concern_user_id = #{userId}  " +
            " AND t1.concern_status = 1  " +
            "GROUP BY " +
            " t1.be_concern_star_id  " +
            "ORDER BY " +
            " concernTime DESC " +
            "</script>")
    List<SwConcernsVo> getSwConcerns(Integer userId);
}
